<html>
<head><meta charset="utf-8"><title>generators and data across yields · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html">generators and data across yields</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="159465705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159465705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159465705">(Feb 26 2019 at 22:44)</a>:</h4>
<p>So <span class="user-mention" data-user-id="127859">@Taylor Cramer</span> we did some more digging after you left. I didn't ever get to the bottom of the <a href="https://github.com/rust-lang/rust/issues/53548" target="_blank" title="https://github.com/rust-lang/rust/issues/53548">#53548</a> but we did dig into <a href="https://github.com/rust-lang/rust/issues/57017" target="_blank" title="https://github.com/rust-lang/rust/issues/57017">#57017</a> and find the code responsible.</p>



<a name="159465718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159465718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159465718">(Feb 26 2019 at 22:44)</a>:</h4>
<p>The basic summary is what I said -- there is an "approximate" check that computes the "generator witness", which is a superset of the data that is really needed.</p>



<a name="159465826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159465826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159465826">(Feb 26 2019 at 22:46)</a>:</h4>
<p>I'll maybe leave some comments on <a href="https://github.com/rust-lang/rust/issues/57017" target="_blank" title="https://github.com/rust-lang/rust/issues/57017">#57017</a>, the relevant code is in <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/generator_interior.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/generator_interior.rs">generator_interior.rs</a>, and particularly <a href="https://github.com/rust-lang/rust/blob/02c4c28920ddfdb43e68a363b7fe59ac4c92399c/src/librustc_typeck/check/generator_interior.rs#L153-L169" target="_blank" title="https://github.com/rust-lang/rust/blob/02c4c28920ddfdb43e68a363b7fe59ac4c92399c/src/librustc_typeck/check/generator_interior.rs#L153-L169">this part of it</a>. It's presently pretty conservative -- it assumes that  the result of each intermediate expression may be stored as long as the enclosing temporary scope.</p>



<a name="159465871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159465871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159465871">(Feb 26 2019 at 22:47)</a>:</h4>
<p>I think we could probably make that more precise by modified the expr-use-visitor and using that to be smarter. This would certainly fix the example in question, though there'd probably still be a measure of imprecision involved. I didn't <em>quite</em> get to seeing clearly the change, have to think on it a bit.</p>



<a name="159466781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159466781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159466781">(Feb 26 2019 at 23:02)</a>:</h4>
<p>I want to compute the generator interior on MIR, which should help with those cases</p>



<a name="159514268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159514268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159514268">(Feb 27 2019 at 13:50)</a>:</h4>
<p><span class="user-mention" data-user-id="116466">@Zoxc</span> I don't think you can necessarily do that -- in particular, we need to know this information during the typeck phase, in order to compute (e.g.) whether something is <code>Send</code>.</p>



<a name="159514382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159514382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159514382">(Feb 27 2019 at 13:51)</a>:</h4>
<p>Further, right now, type checking of the generator is intermingled with type-checking of the surrounding function (this is generally true for closures), so we can't be sure to be able to construct the MIR for the generator until type-checking of the overall fn is complete, and it seems to me that this could depend on whether the generator is <code>Send</code> etc</p>



<a name="159514498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159514498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159514498">(Feb 27 2019 at 13:52)</a>:</h4>
<p>(We could potentially do some sort of best effort thing, and error around cycles, but I'm not sure how I feel about that, I'd like to at least explore if we can compute a better approximation of live data first)</p>



<a name="159515086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159515086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159515086">(Feb 27 2019 at 13:56)</a>:</h4>
<p>We currently generate an error if we try to infer the generator interior of a generator, but don't know all the types inside. That should leave us room to construct MIR just for the generator in the future</p>



<a name="159528637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159528637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159528637">(Feb 27 2019 at 16:20)</a>:</h4>
<p>Which error are you referring to?</p>



<a name="159529245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/159529245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#159529245">(Feb 27 2019 at 16:27)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/generator_interior.rs#L58" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/generator_interior.rs#L58">https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/generator_interior.rs#L58</a></p>



<a name="160029674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/160029674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#160029674">(Mar 05 2019 at 18:56)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> ^this convo seems relevant to the other ongoing thread</p>



<a name="160029707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/160029707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#160029707">(Mar 05 2019 at 18:56)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="120134">@Giles Cope</span></p>



<a name="160030844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/160030844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#160030844">(Mar 05 2019 at 19:08)</a>:</h4>
<p><span class="user-mention" data-user-id="127859">@Taylor Cramer</span> yes I was going to say that :)</p>



<a name="160030852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/generators%20and%20data%20across%20yields/near/160030852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/generators.20and.20data.20across.20yields.html#160030852">(Mar 05 2019 at 19:08)</a>:</h4>
<p>when I mentioned "I have a hunch what the problem is", I was thinking of this...</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>